<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        canvas {
            border: 1px solid #ccc;
        }
    </style>
</head>

<body>
    <canvas id="c1" width="600" height="400"></canvas>

    <script>
        /** @type {HTMLCanvasElement} */
        // 画布
        let c1 = document.getElementById("c1")
        // 画笔
        let ctx = c1.getContext("2d")

        // 对坐标系位移
        ctx.translate(100, 100)
        ctx.fillRect(0, 0, 50, 50)
        ctx.translate(100, 100)
        ctx.fillRect(0, 0, 50, 50)

        // 对坐标系缩放
        ctx.translate(-200, -200)
        ctx.scale(1.2, 1.5)
        ctx.fillRect(0, 0, 50, 50)

        // 以坐标系原点为圆心旋转
        ctx.translate(300, 200)
        ctx.scale(1, 1)
        ctx.rotate(-Math.PI / 4)
        ctx.fillRect(0, 0, 200, 25)
    </script>
</body>

</html>